package uvt.map;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.openstreetmap.gui.jmapviewer.Coordinate;

import uvt.database.Database;
import uvt.database.SelectOperations;
import uvt.map.graph.Drawable;
import uvt.map.graph.Graph;
import uvt.map.graph.element.Segment;
import uvt.map.graph.element.Station;
import uvt.map.mapmarker.MapMarkerDot;
import uvt.map.mapmarker.MapPolygonImpl;

public class ShowElement {
	
	public static void showStations(JMapViewer map) {
		ArrayList<Station> list = new ArrayList<Station>();
	    ((SelectOperations)Database.getInstace()).selectStations(list);		
	    MapMarkerDot.setDotColor(Color.WHITE);
	    MapMarkerDot.setDOT_RADIUS(8 + map.getZoomSlider().getValue() - 19);
	    for(Station st : list) {
	    	Coordinate coord = new Coordinate(st.getLatitude(),st.getLongitude());
			map.addMapMarker(new MapMarkerDot(st.getName(),coord,8 + map.getZoomSlider().getValue() - 19));
	    }
	}
	
    public static void showSegments(JMapViewer map) {
    	TreeMap<String,Segment> list = new TreeMap<String,Segment>();
    	((SelectOperations)Database.getInstace()).selectSegments(list);	
	    MapPolygonImpl.setPolygonColor(Color.red);
	    for(Entry<String,Segment> st : list.entrySet()) {
	    	Segment sg = st.getValue();
	    	ArrayList<Coordinate> coordList = new ArrayList<Coordinate>();
	    	coordList.add(new Coordinate(sg.getxA(),sg.getyA()));
	    	coordList.add(new Coordinate(sg.getxA(),sg.getyA()));
	    	coordList.add(new Coordinate(sg.getxB(),sg.getyB()));
	    	coordList.add(new Coordinate(sg.getxB(),sg.getyB()));
	    	map.addMapPolygon(new MapPolygonImpl("Segment " + st.getKey(),coordList));
	    }
	}
    
    public static void showGraph(JMapViewer map) {
    	Drawable g = new Graph();
	    g.draw(map);
    }
    
    

}
